package net.oschina.app.ui.detail;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import net.oschina.app.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by YL on 2017/4/7.
 */
public class SoftDetailMore extends AppCompatActivity {
    @BindView(R.id.detail_tb)
    Toolbar mDetailTb;
    @BindView(R.id.soft_more)
    WebView mSoftMore;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.soft_detail_more);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    private void initData() {
        mSoftMore.loadUrl(getIntent().getStringExtra("url"));
        WebSettings settings = mSoftMore.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        mSoftMore.setWebViewClient(new MyWebViewClient());
    }
    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
//这里进行url拦截
            if (url != null) {
                return false;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }


        @Override
        public void onPageFinished(WebView view, String url) {
            view.getSettings().setJavaScriptEnabled(true);
            super.onPageFinished(view, url);
        }
    }
    private void initView() {
        mDetailTb.setNavigationIcon(R.drawable.actionbar_back_icon_normal);
        setSupportActionBar(mDetailTb);
        mDetailTb.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.browser_menu,menu);
        return super.onCreateOptionsMenu(menu);
    }
}
